from sqlalchemy import func

from app.models import db


class TrainStation(db.Model):
    __tablename__: str = 'train_station'

    train_no = db.Column(db.String(120), db.ForeignKey('train.train_no'), primary_key=True, index=True)
    station_name = db.Column(db.String(120), db.ForeignKey('station.name'), primary_key=True)

    price = db.Column(db.Numeric(8, 2))
    arrival_time = db.Column(db.DateTime)
    departure_time = db.Column(db.DateTime)
    index = db.Column(db.Integer, default=0)
    created_at = db.Column(db.DateTime, default=func.now())
    updated_at = db.Column(db.DateTime, default=func.now())

    station = db.relationship('Station', backref=db.backref('train_stations'))
    train = db.relationship('Train', backref=db.backref('train_stations'))

